<template>
  <div class="app-declare-container">
    <nu-col :span="24" style="width:100%;height:100%">
      <el-radio-group v-model="examineType" @input="examineTypeInput">
        <el-radio-button label="1">统计历史月份</el-radio-button>
        <el-radio-button label="2">统计年</el-radio-button>
      </el-radio-group>
      <NuVerifyForm :model="formData" ref="formData" label-width="100px" class="submitForm" @submitForm="submitForm"
        :buttons="fyButtons">
        <NuformItem :label="formData.date == 'year' ? '年份' : '月份'" prop="date" width="70%"
          :rules="[{ required: true, message: '日期不能为空' }]">
          <el-date-picker v-model="formData.date" :type="dateType" value-format="yyyy-MM-dd" placeholder="选择日期">
          </el-date-picker>
        </NuformItem>
        <NuformItem label="" prop="date" width="70%">
          <nu-button type="primary" class="searchButton" @click="formSave">重算</nu-button>
        </NuformItem>
      </NuVerifyForm>
    </nu-col>
  </div>
</template>
<script>
import nuCol from "@/components/base/col.vue";
import nutbTitle from "@/components/base/tableTitle.vue";
import NuVerifyForm from "@/components/verify-form";
import NuformItem from "@/components/verify-form/form-item.vue";
import nuInput from "@/components/base/input";
import nuSelect from "@/components/base/select";
import nuButton from "@/components/base/button";
import NuTableList from "@/components/tableList/TableFormList";
import nuRow from "@/components/base/row.vue";
import nuDialog from "@/components/base/dialog";
import { getDateTime } from "@/utils/ruoyi";
export default {
  name: "dataRecalculation",
  components: {
    nuCol,
    nutbTitle,
    NuVerifyForm,
    NuformItem,
    nuInput,
    nuSelect,
    nuButton,
    NuTableList,
    nuRow,
    nuDialog
  },
  data() {
    return {
      currentRow: null,
      formData: {
        date: null
      },
      fyButtons: [],
      examineType: '1',
      dateType: 'month',
    };
  },
  mounted() {
    this.formData.date = getDateTime('day')
  },
  methods: {
    /**
     * 考核input事件
     */
    examineTypeInput(val) {
      if (val == 1) {
        this.dateType = 'month'
      } else {
        this.dateType = 'year'
      }
      this.$nextTick(() => {
        this.$refs['formData'].clearValidate('form');
      })
    },
    /**
     * 重算
     */
    rerunClick() {
      console.log("dasdasdasdsa")
      let postData = {
        ...this.formData
      }
      let examineTypeMap = {
        1: { month: "statisticsMonth", year: "" },
        2: { month: "", year: "statisticsYear" },
      }
      let url = examineTypeMap[this.examineType][this.dateType]
      var reg = new RegExp("-", "g")
      if (this.dateType == 'month') {
        //postData['month'] = getDateTime('day', this.formData.date).replace(reg, "");
        postData['month'] = (getDateTime('month', this.formData.date) + '-01').replace(reg, "");
      } else {
        postData['year'] = getDateTime('year', this.formData.date)
      }
      delete postData.date
      this.$httpGet(window.api[url], postData)
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
          } else {
            this.$message({
              message: res.msg,
              type: "info",
            });
          }
        })
        .catch((err) => {
        });
    },
    /**
     * 重算
     */
    formSave() {
      this.$refs["formData"].submitForm("form");
    },

    /**
     * 重置表单
     */
    resetForm(formName) {
      this.$refs[formName].resetForm('form');
      for (let k in this[formName]) {
        if (Object.prototype.toString.call(this[formName][k]) == "[object String]") {
          this[formName][k] = ''
        } else if (Object.prototype.toString.call(this[formName][k]) == "[object Array]") {
          this[formName][k] = []
        } else if (Object.prototype.toString.call(this[formName][k]) == "[object Number]") {
          this[formName][k] = ''
        }
      }
    },
    /**
     * dialogFormData组件内置提交事件
     */
    submitForm(val) {
      if (val) {
        this.rerunClick()
      }
    },

  },
};
</script>
<style scoped>
.app-declare-container {
  height: calc(100vh - 70px);
}

.hint {
  display: block;
  font-size: 14px;
  line-height: 28px;
  color: rgba(79, 84, 112, 1);
}

.dialogHeaderSearch {
  background-color: var(--model-bgc);
  padding: 10px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: right;
}

.el-col {
  margin: 0;
}

.row {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.col {
  padding: 0px 10px 0px 10px;
}

.submitForm {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  width: 500px;
}

::v-deep .el-form-item {
  margin: 20px 0 0 0;
}
</style>
